/*
 *  GWGaterEffect.cpp
 *  GWGlitch
 *
 *  Created by Michael Forrest on 28/02/2008.
 *  Copyright 2008 Grimaceworks. All rights reserved.
 *
 */

#include "GWGaterEffect.h"

void 	GWGaterEffect::Process(const Float32		*inSourceP,
								Float32		*inDestP,  
								UInt32 		inFramesToProcess,  
								UInt32		inNumChannels,  
								bool		&ioSilence){
		
	UInt32 nSampleFrames = inFramesToProcess;
	const Float32 *sourceP = inSourceP;
	Float32 *destP = inDestP;
	Float32 threshold = kernel->GetParameter(kParam_GaterThreshold);
	while (nSampleFrames-- > 0) {
		Float32 inputSample = *sourceP;
		sourceP += inNumChannels;
		framesHeldBelowThreshold = (fabs(inputSample) > threshold) ? 0 : framesHeldBelowThreshold + 1;
		if(framesHeldBelowThreshold > holdTime ){
			*destP = 0;// previousSample *= decay;
		}else{
			*destP = inputSample;
		}
		destP += inNumChannels;
	}
}